<?php
/**
 * RichCore Forms
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Form
 * @package    Form_Person
 * @copyright  Copyright (c) 2005-2010 RichCongress. (http://www.richcongress.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Add.php 20096 2010-09-23 02:05:09Z benjamin $
 */



class Form_Person_Add extends ZendX_JQuery_Form {
	
	function __construct($options = null, Zend_Translate $translator = null) {
		
		// construct form element
		parent::__construct($options);
		$this->setAction($options['action'])
		     ->setMethod('post')
		     ->setAttrib('class', 'form')
		     ->setAttrib('name', 'person-form')
		     ->setAttrib('id', 'person-form')
		     ->setEnctype(Zend_Form::ENCTYPE_MULTIPART)
		     ->removeDecorator('tag');  
		
		// add hidden parent
		$parent = new Zend_Form_Element_Hidden('parent_structure');
		$parent->addValidator('NotEmpty')
			   ->setValue($options['parent'])    
		       ->setDecorators(array(
					    'ViewHelper',
					    'Description',
					    'Errors',
					    array('HtmlTag', array('tag' => null)),
					    array('Label', array('tag' => null)),
			   ));
			   
		// add person name
		$firstname = new Zend_Form_Element_Text('firstname');
		$firstname->setAutoInsertNotEmptyValidator(true)
			 ->setRequired(true)
	         ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         ->addValidator('NotEmpty')
	         ->setLabel($translator->translate('PERSON FIRSTNAME'))
	         ->setDecorators(array(
					    'ViewHelper',
					    'Description',
					    'Errors',
					    array('HtmlTag', array('tag' => 'span')),
					    array('Label', array('tag' => 'label')),
			 )); 
		
		// add person lastname
		$lastname = new Zend_Form_Element_Text('lastname');
		$lastname->setAutoInsertNotEmptyValidator(true)
			 ->setRequired(true)
	         ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         ->addValidator('NotEmpty')
	         ->setLabel($translator->translate('PERSON LASTNAME'))
	         ->setDecorators(array(
					    'ViewHelper',
					    'Description',
					    'Errors',
					    array('HtmlTag', array('tag' => 'span')),
					    array('Label', array('tag' => 'label')),
			 )); 

		// add person email
		$email = new Zend_Form_Element_Text('email');
		$email->setAutoInsertNotEmptyValidator(true)
			 ->setRequired(true)
	         ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         ->addValidator('NotEmpty')
	         ->setLabel($translator->translate('PERSON EMAIL'))
	         ->setDecorators(array(
					    'ViewHelper',
					    'Description',
					    'Errors',
					    array('HtmlTag', array('tag' => 'span')),
					    array('Label', array('tag' => 'label')),
			 )); 	 

		// add person address
		$address = new Zend_Form_Element_Textarea('address');
		$address->addFilter('StripTags')
		         ->addFilter('StringTrim')
		         ->setAttrib('class', 'textfield')
		         ->setLabel($translator->translate('PERSON ADDRESS'))
		         ->setDecorators(array(
						    'ViewHelper',
						    'Description',
						    'Errors',
						    array('HtmlTag', array('tag' => 'span')),
						    array('Label', array('tag' => 'label')),
				 )); 

		// add person zipcode
		$zipcode = new Zend_Form_Element_Text('zipcode');
		$zipcode->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         ->setAttrib('maxlength', '5')
	         ->setLabel($translator->translate('PERSON ZIPCODE'))
	         ->setDecorators(array(
					    'ViewHelper',
					    'Description',
					    'Errors',
					    array('HtmlTag', array('tag' => 'span')),
					    array('Label', array('tag' => 'label')),
			 )); 		 
		
		// add person city
		$city = new Zend_Form_Element_Text('city');
		$city->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         ->setLabel($translator->translate('PERSON CITY'))
	         ->setDecorators(array(
					    'ViewHelper',
					    'Description',
					    'Errors',
					    array('HtmlTag', array('tag' => 'span')),
					    array('Label', array('tag' => 'label')),
			 ));	

		// add person phone
		$phone = new Zend_Form_Element_Text('telephone');
		$phone->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         ->setAttrib('maxlength', '14')
	         ->setLabel($translator->translate('PERSON PHONE'))
	         ->setDecorators(array(
					    'ViewHelper',
					    'Description',
					    'Errors',
					    array('HtmlTag', array('tag' => 'span')),
					    array('Label', array('tag' => 'label')),
			 ));

		// add person fax
		$fax = new Zend_Form_Element_Text('fax');
		$fax ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         ->setAttrib('maxlength', '14')
	         ->setLabel($translator->translate('PERSON FAX'))
	         ->setDecorators(array(
					    'ViewHelper',
					    'Description',
					    'Errors',
					    array('HtmlTag', array('tag' => 'span')),
					    array('Label', array('tag' => 'label')),
			 ));

		
		//add photo
		$extensions = array('jpg');
		$photo = new Zend_Form_Element_File('photo');
		$photo->setAutoInsertNotEmptyValidator(true)
					 ->setLabel($translator->translate('PERSON PHOTO'))
			         ->setDestination('../temp/uploads/')
			         ->setAttrib('class', 'filefields')
			         ->setAttrib('accept', join('|', $extensions))
			         ->addValidator('Extension', false, join(',', $extensions))
			         ->setDecorators(array(
						'File',
						'Description',
						'Errors',
						array(array('data'=>'HtmlTag'), array('tag' => 'td')),
						array('Label', array('tag' => 'td')),
						array(array('row'=>'HtmlTag'),array('tag'=>'tr')) 
					));			

		$this->addElement($firstname)
			 ->addElement($parent)
			 ->addElement($lastname)
			 ->addElement($photo)
			 ->addElement($email)
			 ->addElement($address)
			 ->addElement($zipcode)
			 ->addElement($city)
			 ->addElement($phone)
			 ->addElement($fax);
	}
}